
package it.csttech.date;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.core.JsonProcessingException;

/**
 * Exception mapper for the JsonProcessingException. build the response with the
 * correct status and the correct message.
 * 
 * @author marcello.felappi
 * @author marco.dalena
 */
@Provider
public class JsonProcessingExceptionMapper
	implements ExceptionMapper<JsonProcessingException> {

	/**
	 * Method that builds the response with the correct status code and message.
	 * 
	 * @param JsonProcessingException
	 *            exception - exception used to build the response with the
	 *            status 400
	 * @return Response response
	 */
	public Response toResponse(JsonProcessingException exception) {

		return Response.status(400).entity(new ErrorObject(exception)).type(
			MediaType.APPLICATION_JSON).build();
	}

}
